upgrade: Don't require specification of osname
authorColin Walters <walters@verbum.org>
Wed, 15 May 2013 12:18:53 +0000 (08:18 -0400)
committerColin Walters <walters@verbum.org>
Wed, 15 May 2013 12:18:53 +0000 (08:18 -0400)
Since this is a highly visible command, let's have a sane default and
upgrade the currently running OS.

src/libgsystem
src/ostree/ot-admin-builtin-upgrade.c
src/ostree/ot-admin-functions.c

index 51736db5f49b4b798fd2f9d0ccb8eff453105162..b2a65b235600e340fada441de7e131de9d52d25e 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 51736db5f49b4b798fd2f9d0ccb8eff453105162
+Subproject commit b2a65b235600e340fada441de7e131de9d52d25e
index f8ee8a0a89716a738e2012263190e293f9157d7e..60def83243790342ce46c68d3fdb3fd406ff1d73 100644 (file)
@@ -40,23 +40,33 @@ ot_admin_builtin_upgrade (int argc, char **argv, OtAdminBuiltinOpts *admin_opts,
   GOptionContext *context;
   gboolean ret = FALSE;
   GFile *ostree_dir = admin_opts->ostree_dir;
+  gs_free char *booted_osname = NULL;
   const char *osname = NULL;
   gs_free char *ostree_dir_arg = NULL;
   __attribute__((unused)) GCancellable *cancellable = NULL;
 
-  context = g_option_context_new ("OSNAME - pull, deploy, and prune");
+  context = g_option_context_new ("[OSNAME] - pull, deploy, and prune");
   g_option_context_add_main_entries (context, options, NULL);
 
   if (!g_option_context_parse (context, &argc, &argv, error))
     goto out;
 
-  if (argc < 2)
+  if (argc > 1)
     {
-      ot_util_usage_error (context, "OSNAME must be specified", error);
-      goto out;
+      osname = argv[1];
+    }
+  else
+    {
+      if (!ot_admin_get_active_deployment (NULL, &booted_osname, NULL, cancellable, error))
+        goto out;
+      if (booted_osname == NULL)
+        {
+          g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+                       "Not in an active OSTree system; must specify OSNAME");
+          goto out;
+        }
+      osname = booted_osname;
     }
-
-  osname = argv[1];
 
   ostree_dir_arg = g_strconcat ("--ostree-dir=",
                                 gs_file_get_path_cached (ostree_dir),
index c0b71a5fcd074c39b494cf9422761a1e6f7b18df..cc0d3b392c56c8c1819421aac42954f2050a9524 100644 (file)
@@ -377,7 +377,7 @@ ot_admin_get_active_deployment (GFile           *ostree_dir,
   if (!ot_admin_get_booted_os (&ret_osname, NULL, cancellable, error))
     goto out;
 
-  if (ret_osname != NULL)
+  if (ret_osname != NULL && out_deployment != NULL)
     {
       gs_unref_object GFile *rootfs_path = NULL;
       gs_unref_object GFileInfo *rootfs_info = NULL;